<div ng-controller="orderListC">
    <div class="bg-light lter b-b wrapper-md">
        <h1 class="m-n font-thin h3">计划单管理</h1>
    </div>
    <div class="wrapper-md" style="text-align: center;">
        <div class="panel panel-default">
            <div class="panel-heading">
                <div class="col-lg-3 col-md-3 col-sm-3 col-xs-12" style="float: right">
                    <a class="btn btn-sm btn-default" href="/api/Order/ExpOrder">
                        <i class="fa fa-cloud-download text"></i>
                        <span class="text">全部导出</span>
                    </a>
                </div>
                <div class="col-lg-6 col-md-6 col-sm-6 col-xs-12 input-group">
                    <!--<input type="text" class="form-control" placeholder="按客户名查找" ng-model="findname">-->
                    <!--<span class="input-group-btn">-->
                        <!--<button class="btn btn-default" type="button" ng-click="find()">查找</button>-->
                    <!--</span>-->
                    <div class="input-group">
                        <span class="input-group-addon">日期查找</span>
                        <input type="date" class="form-control" placeholder="按日期查找" ng-model="startTime">
                        <span class="input-group-addon">模糊查找</span>
                        <input type="text" id="findname" class="form-control" placeholder="客户名\客户经理\供应商模糊查询" ng-model="findname" style="min-width: 100px;">
                        <span class="input-group-addon">按状态查找</span>
                        <select class="form-control" id="typename" ng-model="typename">
                            <option value="">请选择状态</option>
                            <option value="0">待确认</option>
                            <option value="1">驻厂确认</option>
                            <option value="2">已发货</option>
                            <!--<option value="3">已收货</option>-->
                            <option value="4">已结算</option>
                            <!--<option value="5">完结</option>-->
                            <option value="6">取消</option>
                            <option value="7">审核通过</option>
                            <!--<option value="8">已退货</option>
                            <option value="9">已退款</option>-->
                        </select>
                            
                        <span class="input-group-btn">
                            <button class="btn btn-default" type="button" ng-click="find()">查找</button>
                        </span>
                    </div>
                </div>
            </div>
            <div class="table-responsive">
                <table id="example1" class="table table-striped b-t b-light" >
                    <thead>
                    <tr>
                        <th style="text-align: center;">客户名</th>
                        <th style="text-align: center;">客户经理</th>
                        <th style="text-align: center;">供应商</th>
                        <th style="text-align: center;">类型</th>
                        <th style="text-align: center;">金额/重量t</th>
                        <th style="text-align: center;">标注</th>
                        <th style="text-align: center;">地址</th>
                        <th style="text-align: center;">备注</th>
                        <th style="text-align: center;">状态</th>
                        <th style="text-align: center;">创建时间</th>
                        <th style="text-align: center;">详情</th>

                    </tr>
                    </thead>
                    <tbody>
                    <tr ng-repeat="item in orders">
                        <td style="width:10%">{{item.Customer.ShortName}}</td>
                        <td style="width:10%">{{item.Creater.Name}}</td>
                        <td style="width:10%">{{item.Provider.Name}}</td>
                        <td style="width:5%" ng-if="item.Provider.ProviderType == 0">钢厂</td>
                        <td style="width:5%" ng-if="item.Provider.ProviderType == 1">仓库</td>
                        <td style="width:5%" ng-if="item.Provider.ProviderType == 2">贸易商</td>
                        <td style="width:15%">{{item.Total | number:2}}/{{item.Weight | number:3}}t</td>
                        <td style="width:8%">
                            <span ng-if="item.IsFullPayment">先款</span>&nbsp;
                            <span ng-if="item.IsStandard">标件</span>
                        </td>
                        <td style="width:8%">{{item.District.Name}}</td>
                        <td>{{item.Remarks}}</td>
                        <td style="width:8%" ng-if="item.State == 0">待确认</td>
                        <td style="width:8%" ng-if="item.State == 1">驻厂确认</td>
                        <td style="width:8%" ng-if="item.State == 2">已发货</td>
                        <td style="width:8%" ng-if="item.State == 3">已收货</td>
                        <td style="width:8%" ng-if="item.State == 4">已结算</td>
                        <td style="width:8%" ng-if="item.State == 5">完结</td>
                        <td style="width:8%" ng-if="item.State == 6">取消</td>
                        <td style="width:8%" ng-if="item.State == 7">审核通过</td>
                        <td style="width:8%" ng-if="item.State == 8">已退货</td>
                        <td style="width:8%" ng-if="item.State == 9">已退款</td>
                        <td style="width:10%">{{item.CreateTime}}</td>
                        <td style="width:10%">
                            <button class="btn btn-sm btn-default" ng-click="detail($index)">
                                <i class="fa fa-file-text-o text"></i>
                                <span class="text">详情</span>
                            </button>
                        </td>

                    </tr>
                    </tbody>
                </table>
                <!--<div class="panel-heading">-->
                    <!--<div class="panel-heading" ng-include="'/htm/tpl/Supplier/Paging.html'"></div>-->
                <!--</div>-->
                <div class="panel-heading" my-pagination get-page-data="getData" mypagedata="pageData"></div>
            </div>
        </div>
    </div>
</div>
<script>
    angular.module('app')
        //计划单列表控制器
        .controller("orderListC", function ($scope, $state, $http, toSave) {
            $scope.pageData = {};
            $scope.pageData.Page = 0;
            $scope.findname = "";
            $scope.typename = "";
            $scope.order  =  "取消";
            $scope.startTime=new Date();
            
          
            $scope.pageData.Rows = $scope.defPageRows;
            $scope.getData = function (p, r) {
                if (p) {
                    p = p < 1 ? 1 : p;
                } else p = 1;
                if (r) {
                } else r = $scope.defPageRows;
                toSave.save_pages_lis(p,r);//保存当前页码和条数
                if ($scope.startTime==null) {
                    $scope.endDay=new Date(($scope.startTime/1000+86400)*1000);
                    $scope.startTime1="";
                    $scope.endDay1="";
                }else{
                    $scope.endDay=new Date(($scope.startTime/1000+86400)*1000);
                    $scope.startTime1=$scope.startTime.format('yyyy-MM-dd')
                    $scope.endDay1=$scope.endDay.format('yyyy-MM-dd')
                }
                
                  console.log($scope.endDay1, $scope.startTime1)
                $http({
                    url: "../api/Order/List?page=" + p + "&rows=" + r + "&keyword=" + $scope.findname + "&state=" + $scope.typename + "&startTime=" + $scope.startTime1+ "&endTime=" + $scope.endDay1,
                    method: "GET"
                })
                    .then(function (res) {
                        $scope.orders = res.data.Data;
                        console.log($scope.orders)
                        $scope.pageData = res.data;
                    })
                    .then(function (error) {
                        if (error) {
                            alert("数据获取失败");
                        }
                    });
            };
            $scope.save_change = function () {
                console.log($scope.typename);
                localStorage.setItem('c', $scope.typename);
            };
            $scope.get_change = function () {
                var id
                id = localStorage.getItem('c');
                return id
            }
            $scope.detail = function (index) {
                $state.go('app.Order_Detail', {
                    orderid: JSON.stringify($scope.orders[index].Id)
                });
            };
            $scope.find = function () {
                $scope.getData(1, $scope.pageData.Rows);
                $scope.save_change();
                toSave.save_inputs('findname');//点击查询先保存input里面的值
                console.log(toSave.get_inputs('findname'))
            };
            if (toSave.get_inputs('findname') || $scope.get_change() != null) {
                $scope.findname = toSave.get_inputs('findname');//把保存该id名的值取出来赋值给input框
                $scope.typename = localStorage.getItem("c");
                console.log($scope.typename);
              
                $scope.getData(toSave.get_pages(), toSave.get_lis());
            } else {
                $scope.getData(toSave.get_pages(), $scope.pageData.Rows);
            }
        })
</script>

<script src="js/services/toSave.js"></script>